@extends('web.frame_layout')
<?php $parent_menu = "会员管理"; $menu_selected = "覆盖升级";?>
<link rel="stylesheet" href="{{asset('web/css/cover-upgrade.css')}}">
<style>
    .grey {
        background: grey !important;
    }
</style>
@section('content')
        <div class="m-right-nr">
            <div>
                <h2><span>覆盖升级</span></h2>
                <div class="m-vip_up">
                    <form id="m-vip_up" action="{{route('web.up-user.save')}}"  method="post" autocomplete="on">
                        {!! csrf_field() !!}
                        <ul>
                            <li>
                                <label for="vip_level" class="hidden-xs"><i>*</i>当前会员级别：</label>
                                <input type="text" id="vip_level" name="vip_level" value="{{\App\VModels\VVip::vipBySlug($user->vip_slug)->name}}" disabled>
                                <p class="u-ts"></p>
                            </li>
                            <li>
                                <label for="vip_up" class="hidden-xs"><i>*</i>选择晋升等级：</label>
                                <select id="vip_up" name="vip_up">
                                    <option value="0">请选择晋升等级</option>
                                    {{--@foreach($vip_awards  as $vip_award)--}}
                                        {{--@if($vip_award->vip >= $user->vip)--}}
                                            {{--<option value="{{$vip_award ->vip}}">{{uVipStr($vip_award->vip)}}（￥{{uVipByMoney($vip_award->vip)}}）</option>--}}
                                        {{--@endif--}}
                                    {{--@endforeach--}}
                                    @foreach($vips as $vip)
                                        <option value="{{$vip->slug}}">{{$vip->name}} ({{\App\VModels\VVip::attrBySlug($vip->slug)[\App\Models\MUser::$ATTR_ACTIVE]}})</option>
                                    @endforeach
                                </select>
                                <p class="u-ts"></p>
                            </li>
                            <li class="jsjl">
                                <h3 class="u-red">晋升奖励</h3>
                                <input type="text" disabled value="晋升奖励" class="jl_nr">
                            </li>
                            <li>
                                <label for="wallet" class="hidden-xs"><i>*</i>选择钱包：</label>
                                <select id="wallet" name="wallet">
                                    <option value="0">请选择钱包</option>
                                    <option value="{{\App\Models\MWallet::$WALLET_TYPE_1}}">
                                        {{uWalletStr(1)}}（{{$user->wallet->w1 }}）
                                    </option>
                                    <option value="{{\App\Models\MWallet::$WALLET_TYPE_2}}">
                                        {{uWalletStr(2)}}（{{ $user->wallet->w2 }}）
                                    </option>
                                    <option value="{{\App\Models\MWallet::$WALLET_TYPE_3}}">
                                        {{uWalletStr(3)}}（{{ $user->wallet->w3 }}）
                                    </option>
                                </select>
                                <p class="u-ts"></p>
                            </li>
                            <li>
                                <label for="safepass" class="safepass"><i>*</i>交易密码：</label>
                                <input type="password" id="safepass" name="safepass" placeholder="请输入交易密码">
                                <p class="u-ts"></p>
                            </li>
                            <li>
                                <button class="up_user">立即升级</button>
                            </li>
                        </ul>
                    </form>
                </div>
                <div class="table-responsive up-log">
                    <table class="table" rules=rows border="1">
                        <tr>
                            <th>升级前会员级别</th>
                            <th>升级后会员级别</th>
                            <th>升级方式</th>
                            <th>升级时间</th>
                        </tr>
                        @if(!empty($vip_up_logs))
                               @foreach($vip_up_logs as $vip_up_log)
                                <tr class="active">
                                    <td>{{\App\VModels\VVip::vipBySlug($vip_up_log->pre_vip)->name}}</td>
                                    <td>{{\App\VModels\VVip::vipBySlug($vip_up_log->new_vip)->name}}</td>
                                    <td>{{uWalletStr($vip_up_log->method)}}（{{\App\VModels\VVip::attrBySlug($vip_up_log->new_vip)[\App\Models\MUser::$ATTR_ACTIVE]}}）</td>
                                    <td>{{date("Y-m-d H:i:s",$vip_up_log->time)}}</td>
                                </tr>
                                @endforeach
                        @endif
                    </table>
                </div>
            </div>
            {{--<div class="table-responsive up-log">--}}
                {{--<table class="table" rules=rows border="1">--}}
                    {{--<tr>--}}
                        {{--<th>升级前会员级别</th>--}}
                        {{--<th>升级后会员级别</th>--}}
                        {{--<th>升级方式</th>--}}
                        {{--<th>升级时间</th>--}}
                    {{--</tr>--}}
                    {{--<tr class="active">--}}
                        {{--<td>三星渠道专员</td>--}}
                        {{--<td>四星渠道专员</td>--}}
                        {{--<td>奖金币（90000）</td>--}}
                        {{--<td>2017-5-25</td>--}}
                    {{--</tr>--}}
                {{--</table>--}}
            {{--</div>--}}
        </div>
    {{--</div>--}}

@endsection

@section('footer')

    <script type="text/javascript">

        $('#m-vip_up').validate({
            rules: {
                vip_up: {
                    required: true,
                    select: true
                },
                wallet: {
                    required: true,
                    select: true
                },
                safepass:{
                    required: true
                }
            },
            errorPlacement: function (error, element) {
                $(element).siblings('.u-ts').html(error)
            },
            errorElement: 'span',
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    beforeSend: function () {
                        $(".up_user").addClass('grey').attr('disabled', 'disabled');
                    },
                    success: function (data) {
                        $(".up_user").removeClass('grey').removeAttr('disabled');
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location.reload();
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }

        });

        jQuery.validator.addMethod('password', function (value, element) {
            var password = /^[a-zA-Z0-9_-]{6,18}$/.test(value);
            return this.optional(element) || password
        }, '请输入6-18位字母，数字_-');

        jQuery.validator.addMethod('select', function (value, element) {
            return this.optional(element) || (value !== '0')
        }, '请选择相关选项');


        // 生成晋升奖励
        $('#vip_up').change(function () {
            var value=$(this).val();
            switch (value){
                case '0': $('.jl_nr').val(''); break;
                case "{{\App\Models\MUser::$VIP_0}}": $('.jl_nr').val('{{\App\VModels\VVip::attrBySlug(\App\Models\MUser::$VIP_0)[\App\Models\MUser::$ATTR_UPVIP]}}'); break;
                case "{{\App\Models\MUser::$VIP_1}}": $('.jl_nr').val('{{\App\VModels\VVip::attrBySlug(\App\Models\MUser::$VIP_1)[\App\Models\MUser::$ATTR_UPVIP]}}'); break;
                case "{{\App\Models\MUser::$VIP_2}}": $('.jl_nr').val('{{\App\VModels\VVip::attrBySlug(\App\Models\MUser::$VIP_2)[\App\Models\MUser::$ATTR_UPVIP]}}'); break;
                case "{{\App\Models\MUser::$VIP_3}}": $('.jl_nr').val('{{\App\VModels\VVip::attrBySlug(\App\Models\MUser::$VIP_3)[\App\Models\MUser::$ATTR_UPVIP]}}'); break;
            }
        });
    </script>
@endsection